package com.dhy.socket.controller;

import com.dhy.dao.StuDao;
import com.dhy.domain.Stu;
import com.dhy.socket.anno.*;
import com.dhy.socket.res.AjaxResponse;


/**
 * @author 大忽悠
 * @create 2022/6/20 20:31
 */
@Controller
public class StuController {
    private final StuDao stuDao = new StuDao();

    @GetMapping("/listStu")
    public AjaxResponse list(){
        return AjaxResponse.success(stuDao.list());
    }

    /**
     * 查询某位学生成绩
     */
    @GetMapping("/queryStuBySno")
    public AjaxResponse queryStuBySno(@RequestParam("sno") String sno){
          return AjaxResponse.success(stuDao.queryStuBySno(sno));
    }

    @GetMapping("/delOneStu")
    public AjaxResponse delOne(@RequestParam("sno") String sno){
        return AjaxResponse.success(stuDao.deleteStu(sno));
    }

    @PostMapping("/insertOneStu")
    public AjaxResponse insert(@RequestParam("sno")String sno
            ,@RequestParam("name")String name,@RequestParam("credits")Integer credits,@RequestParam("classId")Integer classId) {
        return AjaxResponse.success(stuDao.insert(Stu.builder().sno(sno).name(name).credits(credits).classId(classId).build()));
    }
}
